package com.aps.common.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 基础实体类
 *
 * @author APS Scaffold
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "基础实体类")
public class BaseEntity {

    /**
     * 主键ID
     */
    @Schema(description = "主键ID", example = "1")
    private String id;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "创建时间", example = "2024-01-01 12:00:00")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "更新时间", example = "2024-01-01 12:00:00")
    private LocalDateTime updateTime;

    /**
     * 创建人
     */
    @Schema(description = "创建人", example = "admin")
    private String createBy;

    /**
     * 更新人
     */
    @Schema(description = "更新人", example = "admin")
    private String updateBy;

    /**
     * 删除标记(0:不删除,1:删除)
     */
    @Schema(description = "删除标记", example = "0、1")
    @TableField("del_flag")
    @TableLogic
    private String delFlag;

//    /**
//     * 版本号（乐观锁）
//     */
//    @Schema(description = "版本号", example = "1")
//    private Integer version;
//
//    /**
//     * 备注
//     */
//    @Schema(description = "备注", example = "这是一个示例")
//    private String remark;

    /**
     * 初始化基础字段
     */
    public void initBaseFields() {
        this.createTime = LocalDateTime.now();
        this.updateTime = LocalDateTime.now();
//        this.deleted = false;
//        this.version = 1;
    }

//    /**
//     * 更新基础字段
//     */
//    public void updateBaseFields() {
//        this.updateTime = LocalDateTime.now();
//        this.version = this.version != null ? this.version + 1 : 1;
//    }
}
